package ru.evga.inse.server.gwt.common.client.filter;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;


public abstract class FilterPanel
    extends Composite
{
    interface Binder
        extends UiBinder<HTMLPanel, FilterPanel>
    {
    }
    private static final Binder BINDER = GWT.create(Binder.class);
    @UiField
    SimplePanel filterControlsPanel;
    @UiField
    HasClickHandlers applyFilter;
    @UiField
    HasClickHandlers clearFilter;

    public FilterPanel()
    {
        initWidget(BINDER.createAndBindUi(this));
        applyFilter.addClickHandler(new ClickHandler()
        {
            public void onClick(ClickEvent event)
            {
                applyFilter();
            }
        });
        clearFilter.addClickHandler(new ClickHandler()
        {
            public void onClick(ClickEvent event)
            {
                clearFilter();
            }
        });
    }

    protected void init(Widget filterControls)
    {
        filterControlsPanel.setWidget(filterControls);
    }

    abstract protected void applyFilter();

    abstract protected void clearFilter();
}
